package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.entity.Result;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {
    //注入Redis连接池对象
    @Autowired
    private JedisPool jedisPool;

    public void clearImg(){
        //获取Redis对象
        Jedis resource = jedisPool.getResource();
        //获取Redis中的差值
        Set<String> set = resource.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        for (String fileName : set) {
            QiniuUtils.deleteFileFromQiniu(fileName);
            resource.srem(RedisConstant.SETMEAL_PIC_RESOURCES,fileName);
            System.out.println("自定义删除执行了" + fileName);
        }
        //释放资源
        resource.close();
    }
}
